﻿using System;
using System.Reflection;
using System.Linq;
namespace DeepEarth.Core
{
    /// <summary>
    /// Used exclusively by the map to determine whether to group an item with its parent.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class AtomicFeatureAttribute : Attribute
    {
        public bool GroupItems { get; set; }
        public AtomicFeatureAttribute()
        {
            this.GroupItems = true;
        }

        public AtomicFeatureAttribute(bool groupItems)
        {
            this.GroupItems = groupItems;
        }

        public static bool IsAtomic(object o)
        {
            System.Reflection.MemberInfo info = o.GetType();
            AtomicFeatureAttribute afa = info.GetCustomAttributes(true).OfType<AtomicFeatureAttribute>().FirstOrDefault();

            return (afa != null && afa.GroupItems);
        }
    }
}
